package net.mycrub.bitwise.core.util;

import java.io.InputStream;
import java.io.OutputStream;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

public class SerializationHelper {

    private static Serializer serializer = new Persister();

    public static <T> T read(Class<T> clz, InputStream is)
            throws DeserializationException {
        try {
            return serializer.read(clz, is);
        } catch (Exception e) {
            throw new DeserializationException(clz, e);
        }
    }

    public static void write(Object obj, OutputStream serialized)
            throws SerializationException {
        try {
            serializer.write(obj, serialized);
        } catch (Exception e) {
            throw new SerializationException(obj.getClass(), e);
        }
    }

}
